﻿Imports System.Data.SqlClient

Public Class 计划查询
    Private Sub 查询btn_Click(sender As Object, e As EventArgs) Handles 查询btn.Click

    End Sub

    Function loadJhData()
        ' SQL 查询，列名替换为中文
        Dim sql As String = "
           SELECT 
                ID AS 编号,
                JHBT AS 计划标题,
                JHNR AS 计划内容,
                CASE JLZT 
                    WHEN 1 THEN '未完成'
                    WHEN 0 THEN '已取消' 
                    WHEN 2 THEN '已完成'
                    ELSE '未知状态'
                END AS 记录状态,
                CJSJ AS 创建时间,
                CASE ZYCD
                    WHEN 1 THEN '一般'
                    WHEN 2 THEN '重要'
                    WHEN 3 THEN '非常重要'
                    ELSE '未设置'
                END AS 重要程度,
                KSSJ AS 开始时间,
                JSSJ AS 结束时间,
                XDGW AS 心得感悟
            FROM [dbo].[WDJHK]
            ORDER BY CJSJ DESC
            "


        Try
            Dim dt As New DataTable()

            Using conn As New SqlConnection(DbConnectionHelper.GetConnectString())
                DbConnectionHelper.OpenConnection(conn)

                Using da As New SqlDataAdapter(sql, conn)
                    da.Fill(dt)
                End Using

                DbConnectionHelper.CloseConnection(conn)
            End Using

            ' 绑定 DataGridView
            计划数据_data.DataSource = dt

            If 计划数据_data.Columns.Contains("计划标题") Then
                计划数据_data.Columns("计划标题").FillWeight = 200
            End If

            If 计划数据_data.Columns.Contains("计划内容") Then
                计划数据_data.Columns("计划内容").FillWeight = 250
            End If

            ' 让列宽撑满整个 DataGridView
            计划数据_data.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill



        Catch ex As Exception
            MessageBox.Show("加载支出记录失败：" & ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Function

    Private Sub 计划查询_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        loadJhData()
    End Sub
End Class